<?
//<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
session_start();
require ("inc.php");
$db_admin    = &new db($scfg['db']['admin']);
$rows  = 20;
$page  = (int)($_REQUEST['page']?$_REQUEST['page']:1);
admin_core::check("other@area");

/* 以下是程序部份 */
$db_member = &new db($scfg['db']['member']);
$table 	  = 'area_c1';
if($_POST)
{
	$act = $_POST['act'];
	if($act == 'modify')
	{
		//print_r($_POST);
		//更新
		$a1id = $_POST['a1id'];
		$name = $_POST['name'];
		$taxis = $_POST['taxis'];
		$x = $_POST['x'];
		$y = $_POST['y'];
		$zip = $_POST['zip'];
		if(is_array($a1id))
		{
			foreach($a1id as $k=>$v)
			{
				$bind = array(
					'name'=>$name[$k],
					'taxis'=>$taxis[$k],
					'x'=>$x[$k],
					'y'=>$y[$k],
					'zip'=>$zip[$k]
				);
				$db_member->update($table,$bind," a1id = ? ",$v);
			}
		}
		//刪除
		$del = $_POST['del'];
		if(is_array($del))
		{
			$db_member->delete("area_c1"," a1id in (?) ",$del);
			$db_member->delete("area_c2"," a1id in (?) ",$del);
			$db_member->delete("area_c3"," a1id in (?) ",$del);
		}
	}elseif($act == 'add')
	{
		if($_POST['name'])
		{
			$bind = array(
				'name'=>$_POST['name'],
				'taxis'=>$_POST['taxis'],
				'x'=>$_POST['x'],
				'y'=>$_POST['y'],
				'zip'=>$_POST['zip']
			);
			$id = $db_member->insert($table,$bind);
			if($id)
			{
				echo g::msg("添加成功! ");
			}else
			{
				echo g::msg("失败,请重试! ");
			}
		}
	}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link  href="static/admincp.css" rel="stylesheet" type="text/css" id="css">
<script src="Script/lib.js" 	type="text/javascript"></script>
<script src="Script/lib.ext.js" type="text/javascript"></script>
<script src="Script/lib.ext.oAdmin.js" type="text/javascript"></script>
<script type="text/javascript">
if(typeof XypForm == "undefined")
{
	_.r('<script src="static/xypform/xypfrom.js" type="text/javascript"></sc'+'ript>');
	_.r('<link  href="static/xypform/xypform.css" rel="stylesheet" type="text/css">');
}
var collapsed = $.cookie('DTh_collapse');
function collapse_change(menucount)
{
	if(_.e('menu_' + menucount).style.display == 'none') 
	{
		_.e('menu_' + menucount).style.display = '';collapsed = collapsed.replace('[' + menucount + ']' , '');
		_.e('menuimg_' + menucount).src = 'static/img/menu_reduce.gif';
	} else 
	{
		_.e('menu_' + menucount).style.display = 'none';collapsed += '[' + menucount + ']';
		_.e('menuimg_' + menucount).src = 'static/img/menu_add.gif';
	}
	$.cookie('DTh_collapse', collapsed, 2592000);
}
</script>
</head>
<body leftmargin="10" topmargin="10">
<?

$rs = $db_member->dataArray("select * from {$table} order by a1id,taxis");
//print_r($p);
?>
<form method="post">
<table width="100%" border="0" cellpadding="2" cellspacing="6">
  <tr>
    <td>
        <table width="100%" border="0" cellpadding="0" cellspacing="0" class="tableborder">         
          <tr class="header">
            <td colspan="6" class="tbhead">地區管理</td>
          </tr>
          <tr class="_data_" style="font-weight:bold;">
            <td width="4%" align="right" style="color:#FF0000;">刪?</td>
            <td width="49%" align="left">地區名稱</td>
            <td width="17%" align="left">郵編</td>
            <td width="10%" align="left">排序</td>
            <td width="10%" align="left">經度(x)</td>
            <td width="10%" align="left">緯度(y)</td>
          </tr>
 <?
  	if(is_array($rs))
	{
		foreach($rs as &$v)
		{
?>
			<tr class="_data_">
			<input name="a1id[<?=$v['a1id']?>]" type="hidden" value="<?=$v['a1id']?>" />
			<td width="4%" align="right"><input type="checkbox" name="del[]" value="<?=$v['a1id']?>" /></td>
			<td align="left"><input name="name[<?=$v['a1id']?>]" type="text" value="<?=$v['name']?>" size="32" maxlength="32" />
			> <a href="_other_area_a2.php?a1id=<?=$v['a1id']?>">进入次級地區</a></td>
			<td align="left"><input name="zip[<?=$v['a1id']?>]" type="text" value="<?=$v['zip']?>" size="2" maxlength="10" /></td>
			<td align="left"><input name="taxis[<?=$v['a1id']?>]" type="text" value="<?=$v['taxis']?>" size="2" maxlength="10" /></td>
			<td align="left"><input name="x[<?=$v['a1id']?>]" type="text" value="<?=$v['x']?>" size="2" maxlength="10" /></td>
			<td align="left"><input name="y[<?=$v['a1id']?>]" type="text" value="<?=$v['y']?>" size="2" maxlength="10" /></td>
			</tr>
			<?
		}
	}

  ?>
         <tr class="_data_">
            <td>&nbsp;</td>
            <td colspan="5"><input name="Submit" type="submit" class="bginput" value="  送 出 " >
            <input name="Submit" type="reset" class="bginput" value=" 重 設 ">
            <input name="act" type="hidden" id="act" value="modify"></td>
          </tr>
        </table>
        </td>
  </tr>
</table>
</form>
  
 <hr />
<form name="addcats" method="post" onsubmit="return chk(this)">
<table width="100%" border="0" cellpadding="2" cellspacing="6">
  <tr>
    <td>
        <table width="100%" border="0" cellpadding="0" cellspacing="0" class="tableborder">         
          	 <tr class="header">
                <td colspan="2" class="tbhead">添加地區名稱</td>
              </tr>
              <tr class="_data_">
                <td align="right">地區名稱：</td>
                <td align="left"> 
                 <input name="name" type="text" id="name" size="20" maxlength="32">
                 (必选)</td>
              </tr>
              <tr class="_data_">
                <td width="14%" align="right">郵編：        </td>
                <td width="86%" align="left"><input name="zip" type="text" id="zip" size="10" maxlength="10">
                  (必选)</td>
              </tr>
              <tr class="_data_">
                <td align="right" valign="top">排序：</td>
                <td align="left"><input name="taxis" type="text" id="taxis" value="0" size="10" maxlength="10" />
                  (可选)</td>
              </tr>
              <tr class="_data_">
                <td align="right" valign="top">經度(x)：</td>
                <td align="left"><input name="x" type="text" id="x" size="10" maxlength="10" />
                  (可选)</td>
              </tr>
              <tr class="_data_">
                <td align="right" valign="top">緯度(y)：</td>
                <td align="left"><input name="y" type="text" id="y" size="10" maxlength="10" />
                  (可选)</td>
              </tr>
              <tr class="_data_">
                <td>&nbsp;</td>
                <td><input type="submit" class="bginput" value="送出">
                <input type="reset" class="bginput" value="重設">
                <input name="act" type="hidden" id="act" value="add"></td>
              </tr>
        </table>
        </td>
  </tr>
</table>
</form>

<script language="JavaScript" type="text/JavaScript">
<!--
var chk = function(o)
{
	if(XypFrom.chk(o.name,'','请输入分類名稱!'))
	{
		return false;
	}else if(XypFrom.chk(o.taxis,'nums'))
	{
		return false;
	}else
	{
		return true;
	}
};
//---->
</script>
<br />
<? include("s_tpl.copyright.php"); ?>
</body>
</html>